﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace XFGameFramework
{

    public class Vector2Extensions : MonoBehaviour
    {
        public static float InverseLerp(Vector2 from, Vector2 to, Vector2 current)
        {
            float lerp = Mathf.InverseLerp(from.x, to.x, current.x);

            if (lerp > 0 && lerp <= 1)
            {
                if (Vector2.Distance(current, Vector2.Lerp(from, to, lerp)) <= 0.01f)
                    return lerp;
            }

            lerp = Mathf.InverseLerp(from.y, to.y, current.y);

            if (lerp > 0 && lerp <= 1)
            {
                if (Vector2.Distance(current, Vector2.Lerp(from, to, lerp)) <= 0.01f)
                    return lerp;
            }
              
            return 0;
        }

    }
}